import time

from selenium.webdriver.common.by import By
from unit__003.unit_04.Base.Base import Base


class Page(Base):
    # 元素定位
    # 封装的元素操作方法

    # 1.点击请登录 href="https://login.jiuxian.com/login.htm"
    qlogin_loc = (By.XPATH, '//a[@href="https://login.jiuxian.com/login.htm"]')

    def click_qlogin(self):
        self.click(self.qlogin_loc)

    # 2.输入账号 id="userName"
    username_loc = (By.ID, 'userName')

    def sr_username(self,username):
        self.send_keys(self.username_loc, username)

    # 3.输入密码 id="password"
    password_loc = (By.ID, 'password')

    def sr_password(self,password):
        self.send_keys(self.password_loc, password)

    # 4.点击登录 name="bi_Usuallogin"
    login_loc = (By.NAME, 'bi_Usuallogin')

    def click_login(self):
        self.click(self.login_loc)

    # 5.点击确定 id="bindSub"
    qd_loc = (By.XPATH, '/html/body/div/div[4]/div[2]/div[2]/a')

    def click_queding(self):
        self.click(self.qd_loc)

    # 断言-jxw824726828 /html/body/div[2]/div/div[1]/div/p/span

    # 酒仙-登录逻辑业务
    def jiuxian_login(self,username,password):
        self.open_url('https://www.jiuxian.com/')
        time.sleep(3)
        # 1.点击请登录
        self.click_qlogin()
        time.sleep(2)
        # 2.输入账号
        self.sr_username(username)
        time.sleep(2)
        # 3.输入密码
        self.sr_password(password)
        time.sleep(10)
        # 4.点击登录
        self.click_login()
        time.sleep(2)
        # 5.点击确定
        self.click_queding()
